import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../main.dart';
import '../../../r.dart';
import '../../../utils/DialogUtils.dart';
import '../../../values/MyColors.dart';
import 'set_logic.dart';

class SetPage extends StatefulWidget {
  final String title;

  const SetPage({Key? key, required this.title}) : super(key: key);

  @override
  State<SetPage> createState() => _SetPageState();
}

class _SetPageState extends State<SetPage> {
  final logic = Get.put(SetLogic());
  final state = Get.find<SetLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SetLogic>(builder: (logic) {
      return Scaffold(
        backgroundColor: MyColors.FFEDF1F5,
        appBar: BrnAppBar(title: "设置", themeData: XxxConfigUtils.defaultAppBarConfig),
        body: Column(
          children: [
            Container(
              margin: EdgeInsets.only(left: 16.r, right: 16.r, top: 10.r, bottom: 0.r),
              child: BrnShadowCard(
                color: Colors.white,
                circular: 6.r,
                spreadRadius: 0.11.r,
                blurRadius: 0.4.r,
                child: Container(
                  height: 52.r,
                  padding: EdgeInsets.only(left: 15.r, right: 15.r, top: 8.r, bottom: 8.r),
                  child: InkWell(
                    onTap: () {
                      dialogUtils.show(
                        context: context,
                        title: "提示",
                        content: "确定清除缓存？",
                        callbackOk: () {
                          logic.clearAllCache();
                        },
                      );
                    },
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Image.asset(R.assetsImgIconMy11, width: 15.r),
                            Padding(
                              padding: EdgeInsets.only(left: 9.5.r),
                              child: Text("清除缓存", style: TextStyle(color: MyColors.FF333333, fontSize: 14.r)),
                            ),
                          ],
                        ),
                        Row(
                          children: [
                            Padding(
                              padding: EdgeInsets.only(right: 9.5.r),
                              child: Text(state.dataNum, style: TextStyle(color: MyColors.FF999999, fontSize: 12.r)),
                            ),
                            Image.asset(R.assetsImgIconMy5, width: 5.5.r),
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 16.r, right: 16.r, top: 10.r),
              child: BrnShadowCard(
                color: Colors.white,
                circular: 6.r,
                spreadRadius: 0.11.r,
                blurRadius: 0.4.r,
                child: Container(
                  height: 52.r,
                  padding: EdgeInsets.only(left: 15.r, right: 15.r, top: 8.r, bottom: 8.r),
                  child: InkWell(
                    onTap: () {},
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Image.asset(R.assetsImgIconMy11, width: 15.r),
                            Padding(
                              padding: EdgeInsets.only(left: 9.5.r),
                              child: Text("版本号", style: TextStyle(color: MyColors.FF333333, fontSize: 14.r)),
                            ),
                          ],
                        ),
                        Row(
                          children: [
                            Padding(
                              padding: EdgeInsets.only(right: 9.5.r),
                              child: Text(state.version, style: TextStyle(color: MyColors.FF999999, fontSize: 12.r)),
                            ),
                            Image.asset(R.assetsImgIconMy5, width: 5.5.r),
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 16.r, right: 16.r, top: 10.r),
              child: BrnShadowCard(
                color: Colors.white,
                circular: 6.r,
                spreadRadius: 0.11.r,
                blurRadius: 0.4.r,
                child: Container(
                  height: 52.r,
                  padding: EdgeInsets.only(left: 15.r, right: 15.r, top: 8.r, bottom: 8.r),
                  child: InkWell(
                    onTap: () {
                      logic.goToAgreementWebViewPage();
                    },
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Image.asset(R.assetsImgIconMy11, width: 15.r),
                            Padding(
                              padding: EdgeInsets.only(left: 9.5.r),
                              child: Text("用户协议和隐私政策", style: TextStyle(color: MyColors.FF333333, fontSize: 14.r)),
                            ),
                          ],
                        ),
                        Image.asset(R.assetsImgIconMy5, width: 5.5.r),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 32.r, right: 32.r, top: 50.r),
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.all(0),
                  backgroundColor: MyColors.FF1060DD,
                  shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),
                  minimumSize: Size(MediaQuery.of(context).size.width, 45.r),
                ),
                onPressed: () {
                  logic.loginOut();
                },
                child: Text("退出", style: TextStyle(color: Colors.white, fontSize: 13.r)),
              ),
            ),
          ],
        ),
      );
    });
  }

  @override
  void dispose() {
    Get.delete<SetLogic>();
    super.dispose();
  }
}
